package ModelLayer;
import java.util.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.time.*;

/**
 * Write a description of class Lease here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Lease
{
    private int leaseId;
    private String leaseDate;
    private String period;
    private boolean state;
    private ArrayList<LeaseLine> leaseLine;
    private Customer myCustomer;
    public Lease(int leaseId, String leaseDate, String period, boolean state)
    {
        this.leaseDate = leaseDate;
        this.leaseId = leaseId;
        this.period = period;
        this.state = state;
        leaseLine = new ArrayList<LeaseLine>();
        
        
    }

    public boolean onTime(){
        try{
            String dt = this.leaseDate;  
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar c = Calendar.getInstance();

            c.setTime(sdf.parse(dt));

            c.add(Calendar.DATE, Integer.parseInt(this.period));  // number of days to add
            dt = sdf.format(c.getTime());  // dt is now the new date

            Date currentDate = new Date();
            Date date = sdf.parse(dt);

            if(date.before(currentDate)){
                return false;
            }else{
                return true;
            }

        }catch(Exception e){
            return false;
        }

    }

    //SETTERS

    public void setLeaseDate(String newLeaseDate)
    {
        leaseDate = newLeaseDate;
    }

    public void setPeriod(String period){
        this.period = period;
    }

    public void setState(boolean state){
        this.state = state;
    }
    
    public void setLeaseId(int newId)
    {
        leaseId = newId;
    }
    
    public void addLeaseLine(LeaseLine l)
    {
        leaseLine.add(l);
    }
    
    //GETTERS

    public String getLeaseDate()
    {
        return leaseDate;
    }

    public String getPeriod(){
        return period;
    }

    public boolean getState(){
        return state;
    }
    
    public int getLeaseId()
    {
        return leaseId;
    }
}
